package com.fr.report.script.function;

import com.fr.base.FRContext;
import com.fr.data.TableData;
import com.fr.data.TableDataException;
import com.fr.data.core.DataUtils;
import com.fr.report.script.Calculator;
import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ROWCOUNT extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    String str = paramArrayOfObject[0].toString();
    Calculator localCalculator = getCalculator();
    TableData localTableData = DataUtils.getTableData4Function(localCalculator, str);
    try
    {
      return new Integer(localTableData.getRowCount());
    }
    catch (TableDataException localTableDataException)
    {
      FRContext.getLogger().log(Level.WARNING, localTableDataException.getMessage(), localTableDataException);
    }
    return new Integer(0);
  }

  public Function.Type getType()
  {
    return Function.REPORT;
  }

  public String getCN()
  {
    return "ROWCOUNT(tableData)返回tableData的行数。\ntableData:TableData的名字，字符串形式的。\n备注:\n    先从私有数据源中查找，然后再从公有数据源中查找，返回的是tableData的行数。\n示例:\n以我们提供的数据源FRDemo为例\nROWCOUNT(\"Check\")等于3。\nROWCOUNT(\"country\")等于18。";
  }

  public String getEN()
  {
    return "";
  }
}